<template>
  <div id="edit">
    <div class="main-content clearfix">
      <article class="container">
        <div class="article-main">
          <div class="new-edit-article"><h3>新建文章</h3></div>
          <input class="edit-title" placeholder="请输入标题"/>
          <div id="editor">
            <textarea :value="input" @input="update"></textarea>
            <div v-html="compiledMarkdown"></div>
          </div>
        </div>
        <div class="save-wrapper">
          <a href="#" class="save-btn">保存</a>
          <a href="#" class="publish-btn">发布</a>
        </div>
        <sidebar></sidebar>

      </article>
    </div>
  </div>
</template>

<script>
  import sidebar from '../components/tag.vue'

  export default {
    name: 'edit',
    components: {
      sidebar,
    },
    data() {
        return{
          input: '# Markdown 编辑器'
        }
    },
    computed: {
      compiledMarkdown: function () {
        return marked(this.input, { sanitize: true })
      }
    },
    methods: {
      update: _.debounce(function (e) {
        this.input = e.target.value
      }, 300)
    }
  }
</script>

<style scoped>
  .main-content {
    margin: 40px auto;
    max-width: 1400px;
    padding: 0 24px;
    position: relative;
  }

  .article-main {
    float: left;
    width: calc((100% - 30px) / 3 * 2);
    margin-right: 40px;
  }

  .new-edit-article {
    margin-top: 26px;
  }

  .new-edit-article h3 {
    margin: 0;
    line-height: 36px;
  }

  .side-item select {
    background: #fff;
    width: 100px;
    height: 36px;
    line-height: 36px;
    border: 1px solid #e7e7e7;
    color: #777;
    border-radius: 4px;
    padding-left: 6px;
    outline: none;
    box-sizing: border-box;
    margin-right: 10px;
    cursor: pointer;
  }

  .side-item label {
    color: #777;
    font-size: 18px;
    padding-right: 20px;
    line-height: 36px;
    cursor: pointer;
    font-weight: normal;
    -moz-user-select: none;
  }

  .edit-title {
    width: 100%;
    height: 36px;
    line-height: 36px;
    margin: 15px 0 20px 0;
    padding: 0 20px;
    outline: none;
    border: 1px solid #e7e7e7;
    box-shadow: 0 0 3px rgba(0, 0, 0, .15);
  }

  .save-wrapper {
    position: absolute;
    right: 96px;
    top: 26px;
  }

  .save-wrapper a {
    display: inline-block;
    width: 100px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    border-radius: 4px;
  }

  .save-btn {
    background: #fff;
    color: #387aff;
  }

  .publish-btn {
    background: #387aff;
    color: #fff;
    margin-left: 20px;
  }

  /*markdowm*/

  html, body, #editor {
    margin: 0;
    height: 500px;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    color: #333;
  }

  textarea, #editor div {
    display: inline-block;
    width: 49%;
    height: 100%;
    overflow: auto;
    vertical-align: top;
    box-sizing: border-box;
    padding: 0 20px;
  }

  textarea {
    border: none;
    border-right: 1px solid #ccc;
    resize: none;
    outline: none;
    background-color: #f6f6f6;
    font-size: 14px;
    font-family: 'Monaco', courier, monospace;
    padding: 20px;
  }

  code {
    color: #f66;
  }

</style>
